<!--
 * @author cuiliuhao
   打卡活动排行榜
 -->
<template>
  <section class="special-rush-rank">
    <section class="main-inner">
      <div class="btn-box">
        <el-button @click="exportFun">导出排行榜</el-button>
      </div>
      <section class="inner-table">
        <el-table v-loading="listLoading" :data="list" style="width: 100%">
          <el-table-column
            prop="clockRank"
            label="排名"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span v-if="scope.row.clockRank == 1" class="svg-container medal">
                <svg-icon icon-class="gold-medal" />
              </span>
              <span v-if="scope.row.clockRank == 2" class="svg-container medal">
                <svg-icon icon-class="silver-medal" />
              </span>
              <span v-if="scope.row.clockRank == 3" class="svg-container medal">
                <svg-icon icon-class="copper-medal" />
              </span>
              <span v-if="scope.row.clockRank > 3" class="svg-container">{{
                scope.row.clockRank
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="userView"
            label="头像"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <el-image
                style="width: 50px; height: 50px"
                :src="view + scope.row.userView"
                :preview-src-list="[view + scope.row.userView]"
              >
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline" />
                </div>
              </el-image>
            </template>
          </el-table-column>
          <el-table-column
            prop="userRealname"
            label="姓名"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column
            prop="userPhonenumber"
            label="电话"
            align="center"
            show-overflow-tooltip
            :formatter="formatterData"
          />
          <el-table-column
            prop="clockDayNum"
            label="打卡天数"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column
            prop="learnDurationValue"
            label="学习时长"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column
            prop="passCount"
            label="通关次数"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column
            prop="shareNum"
            label="分享次数"
            align="center"
            show-overflow-tooltip
          />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.limit"
          @pagination="getList"
        />
      </section>
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import { rankQueryPage, exportMask, exportNoMask } from './../api'
import { exportSign } from '@/utils/fileImportOrExportSign'
import CryptoJS from '@/utils/aesJiaJM'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
export default {
  name: 'PunchRanking',
  components: { Pagination },
  data() {
    return {
      view: '/API-DOCUMENT/document/file/download?id=',
      search: {
        userRealName: '',
        rushQuestionId: '',
        type: 'ACTIVITY',
        type2: ''
      },
      listQuery: {
        page: 1,
        limit: 10
      },
      activityId: '',
      total: 0,
      listLoading: false,
      list: [],
      rushs: [],
      centerDialogVisible: false,
      form: {
        rankNumLimit: 0,
        certification: '0'
      },
      rule: {
        rankNumLimit: [
          { required: true, message: '请输入导出排名数量', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    if (this.$route.query.i === '') {
      this.$message({
        message: '参数异常',
        type: 'error'
      })
      return false
    } else {
      this.activityId = this.$route.query.i
    }
    this.getList()
    // this.getRush()
  },
  methods: {
    exportFun() {
      var query = exportSign({
        activityId: this.activityId
      }).obj
      exportCheck(
        'CLOCK_ACTIVITY',
        this.$route.query.i,
        exportMask,
        exportNoMask,
        query,
        '排行榜.xlsx'
      ) // 导出脱敏或者不脱敏表格
      // this.centerDialogVisible = false
    },

    // 获取排行榜列表数据
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        activityId: this.activityId
      }
      return new Promise((resolve, reject) => {
        rankQueryPage(query)
          .then((res) => {
            console.log(res, 145)
            this.listLoading = false
            this.list = res.data.data.rows
            this.total = res.data.data.total
          })
          .catch((error) => {
            this.listLoading = false
            reject(error)
          })
      })
    },

    formatterData(row, col) {
      return CryptoJS.$aesJieM(row.userPhonenumber)
    }
  }
}
</script>
<style lang="scss">
.special-rush-rank {
  padding: 10px;

  .el-tabs {
    padding: 0 10px;
    background-color: #fff;

    .el-tabs__header {
      margin: 0;
    }

    .el-tabs__nav-wrap::after {
      height: 0;
    }
  }

  .btn-box {
    text-align: right;
    margin-bottom: 10px;
  }

  .not-data {
    width: 100%;
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    size: 18px;
    color: #999;
  }

  .main-inner {
    margin-top: 10px;

    .inner-table {
      .medal {
        font-size: 24px;
      }

      .el-image .image-slot {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
        background: #f5f7fa;
      }
    }
  }
}
</style>
